package jrobutt;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class GameFrame
{
    public static void main (String[] argv)
    {
        if (argv.length > 0)
        {
            if (argv[0].equals("-v") || argv[0].equals("--version"))
            {
                System.out.println("JRobutt v" + Settings.vstring);
                return;
            }
            if (argv[0].equals("-g") || argv[0].equals("--version-gui"))
            {
                try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
                catch (Exception ex) {}
                JOptionPane.showMessageDialog(null, "JRobutt v" + Settings.vstring);
                return;
            }
        }
        
        final JFrame parent = new JFrame("JRobutt v" + Settings.vstring);
        parent.setIconImage(Global.image_loader.load("window_icon.png", false));
        final JRobuttComponent child = new JRobuttComponent();
        
        parent.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        parent.addWindowListener(new WindowAdapter() {
            public void windowClosing (WindowEvent ev)
            {
                child.stop();
                parent.dispose();
            }
        });
        // public void parent.init (Dimension size)
        {
            child.setGameoverListener(new GameoverListener() {
                public void gameIsOver ()
                {
                    parent.dispose();
                }
            });
            Dimension size = new Dimension(Settings.width, Settings.height);
            child.setPreferredSize(size);
            parent.add(child);
            parent.pack();
            child.init(size);
        }
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension size = parent.getSize();
        parent.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2);
        parent.setVisible(true);
    }
}
